{% extends "./inc/base.html" %}
{% block style%}
<link rel="stylesheet" href="/static/admin/js/datepicker/bootstrap-datetimepicker.min.css" type="text/css">
{% endblock %}
{% block content %}
    <section class="hbox stretch">
    <section class="vbox">
        <header class="header bg-light dk">

            <p>会员管理</p>
        </header>
        <section class="scrollable wrapper">

            <section class="panel panel-default">
                <header class="panel-heading clearfix">
                    <ul class="nav nav-tabs pull-left">
                        <li {%if zhucestatus==1%} class="active" {%endif%}><a href="/admin/user/shenhe/?zhucestatus=1">未审核</a></li>
                        <li {%if zhucestatus==3%} class="active" {%endif%}><a href="/admin/user/shenhe/?zhucestatus=3">已审核</a></li>
                    </ul>
                </header>
                {%if zhucestatus!=1%}
                <div class="input-group pull-left search-form">
                    <input  type="hidden"  name="zhucestatus"  value="{{controller.get('zhucestatus')}}">
                    <a >用户姓名&nbsp&nbsp</a><input  type="text" name="real_name"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >电话号码&nbsp&nbsp</a><input  type="text"  name="mobile"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >公司/商户名称&nbsp&nbsp</a><input  type="text" name="gsmc"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >会员类型&nbsp&nbsp</a>
                    <select class=" input-sm " name="groupid" >
                        <option style='display: none'></option>
                        <option value="11">普通会员</option>
                        <option value="12">核心企业</option>
                    </select>
                    <span class="input-group-btn" >
                            <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/user/shenhe">搜索</button>
                            <button class="btn btn-sm btn-btn-sm" type="button" id="exportCSV" url="/admin/user/export/?modelexp=1"><i class="fa fa-download"></i>导出列表</button>
                        </span>
                </div>
                {%endif%}
                <!--<div class="row wrapper">

                    &lt;!&ndash;<div class="col-sm-9 m-b-xs">
                        <div class="">
                            <a href="/admin/user/adduser" class="btn btn-sm btn-info " data-toggle="ajaxModal">
                                添加用户
                            </a>
                            <a class="btn btn-sm btn-info ajax-post" href="/admin/user/setstatus/?status=1&model=member"  target-form="ids">
                                启用
                            </a>
                            <a class="btn btn-sm btn-info ajax-post" href="/admin/user/setstatus/?status=0&model=member" target-form="ids">
                                禁用
                            </a>
                            <a class="btn btn-sm btn-info ajax-post confirm" href="/admin/user/userdel" target-form="ids">
                                删除
                            </a>
                        </div>
                    </div>&ndash;&gt;
                    &lt;!&ndash;<div class="col-sm-3">
                        <div class="input-group pull-right search-form">
                            <input type="text" class="input-sm form-control" name="username" placeholder="请输入用户名"
                                   value="{{controller.get('username')}}">
                            <span class="input-group-btn">
                        <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/user/index">搜索</button>
                      </span>
                        </div>
                    </div>&ndash;&gt;
                </div>-->
                <div class="table-responsive ">
                    <table class="table table-striped b-t b-light">
                        <thead>
                        <tr>
                            <th style="width:20px;"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                            <th class="">会员名称</th>
                            <th class="">会员主体</th>
                            <th class="">公司/商户名称</th>
                            <th class="">身份证号码</th>
                            {%if zhucestatus!=1%}
                            <th class="">纳税人识别号</th>
                            {%endif%}
                            <th class="">电话号码</th>
                            {%if zhucestatus!=1%}
                            <th class="">会员类型</th>
                            <th class="">员工编号</th>
                            {%endif%}
                            <th class="">认证申请时间</th>
                            {%if zhucestatus!=1%}
                            <th class="">认证审核时间</th>
                            <th class="">认证状态</th>
                            {%endif%}
                            <th class="">会员信息</th>
                            {%if zhucestatus!=1%}
                            <th class="">备注</th>
                            {%else%}
                            <th >操作</th>
                            {%endif%}

                        </tr>
                        </thead>
                        <tbody>
                        {% for item in list %}
                        <!--{%set group=item.groupid|get_member_group%}-->
                        <tr>
                            <td><label class="checkbox m-n i-checks"><input class="ids" type="checkbox" name="ids" value="{%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}{{item.id}}{%endif%}" {%if item.id|in_Array(controller.config('user_administrator'))%}disabled="true"{%endif%}><i></i></label></td>
                            <td>{{item.real_name}} </td>
                            <td>{%if item.org_type==0%}个人{%else%}企业(个体){%endif%}</td>
                            <td>{{item.gsmc}} </td>
                            <td>{{item.user_code}}</td>
                            {%if zhucestatus!=1%}
                            <td>{{item.nsrsbh}}</td>
                            {%endif%}
                            <td>{{item.mobile}}</td>
                            {%if zhucestatus!=1%}
                            <td>{%if item.groupid==11%}普通会员{%else%}核心企业{%endif%}</td>
                            <td>{{item.ygbh}}</td>
                            {%endif%}
                            <td>{%if item.update_time=="0"%}空{%else%}{{item.update_time| moment('YYYY-MM-DD HH:mm:ss')}}{%endif%}</td>
                            {%if zhucestatus!=1%}
                            <td>{%if item.shenheshijian==null%}空{%else%}{{item.shenheshijian| moment('YYYY-MM-DD HH:mm:ss')}}{%endif%}</td>
                            <td >{%if item.zhucestatus ==2 %}<span> 已通过</span>{%elif item.zhucestatus ==-1 %}<span> 已驳回</span>{%endif%}</td>
                            {%endif%}
                            <td><a href="/admin/user/showuser/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">查看<i class="fa fa-search-plus"></i> </a> </td>
                            {%if zhucestatus!=1%}
                            <td><a href="/admin/order/viewremarks/?id={{item.id}}&model_name={{controller.tactive}}" class="text-info" data-toggle="ajaxModal">查看</a></td>
                            {%else%}
                            <td>
                                <a href="/admin/user/editshenhe/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">编辑</a>
                                {%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}
                                <a href="/admin/user/shenhebohui/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">驳回</a>
                                {%endif%}
                            </td>
                            {%endif%}
                        </tr>
                        {% else %}
                        <tr><td colspan="7"><div class="alert alert-warning alert-block">
                            <button data-dismiss="alert" class="close" type="button">×</button>
                            <p>暂无数据</p>
                        </div></td></tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <footer class="panel-footer">
                    <div class="row">


                        <div class="col-sm-12 text-right text-center-xs">
                            {{pagerData | safe}}
                        </div>
                    </div>
                </footer>
            </section>
        </section>
    </section>
    </section>
{% endblock%}

{% block script%}
<script src="/static/admin/js/parsley/parsley.min.js"></script>
<script src="/static/admin/js/parsley/parsley.extend.js"></script>
<script src="/static/admin/js/datepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="/static/admin/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<script>
$(function () {

    function isPriceNumber(_keyword){
        if(_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00"){
            _keyword = "0"; return true;
        }else{
            var index = _keyword.indexOf("0");
            var length = _keyword.length;
            if(index == 0 && length>1){/*0开头的数字串*/
                var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }else{/*非0开头的数字*/
                var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }
            return false;
        }
    }
    $(document).on('click', ".recharge", function (e) {
        var balance = $("input[name='balance']").val();
        var name = $("input[name = 'name']").val();
        var id = $("input[name = 'id']").val();
        if(!isPriceNumber(balance)){
            swal( "请填写正确的价格.");
            return false;
        }
        swal({
            title: "确认您的操作！",
            text: "您将给 "+name+" 充值 "+balance+" 元！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定充值!",
            cancelButtonText: "关闭!",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                url:"/admin/user/recharge",
                data:{balance:balance,id:id},
                type:"POST",
                success:function (res) {
                    if(res.errno == 0){
                        swal(res.data.name, "", "success");
                        $('#ajaxModal').modal('hide');
                        location.reload();
                    }

                }
            })

        });
    })
    //搜索功能
    $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
        window.location.href = url;
    });
  $("#exportCSV").click(function(){
    var url = $(this).attr('url');
    var query  = $('.search-form').find('input,select').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
  });

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
})
</script>
{% endblock %}
